package com.bittech.servlet.smallfileserver.web.api;

import com.bittech.servlet.smallfileserver.service.FileService;
import com.bittech.servlet.smallfileserver.service.impl.FileServiceImpl;

import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Author: secondriver
 * Created: 2018/8/27
 */
@WebServlet(urlPatterns = {"/api/delete"})
@MultipartConfig
public class FileApiDeleteServlet extends FileApiBaseServlet {
    
    private FileService fileService = new FileServiceImpl();
    
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
        try {
            String id = req.getParameter("id");
            fileService.removeFile(id);
            this.sendData(resp, true, "");
        } catch (Exception ignored) {
            this.sendData(resp, false, "Delete failed");
        }
    }
}